package com.zhou;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: zhouweixin
 * @Description:
 * @Date: Created in 13:09 2018/10/26
 * @Modified By:
 */
public class Config {
    // 固定参数
    private String url = "http://www.wanfangdata.com.cn/searchResult/getCoreSearch.do?d=0.9965202107587834";
    private String updateDate = "";
    private int pageNum = 1;
    private int totalPageNum = 0;
    private int totalNum = 0;
    private String sortFiled = "";
    private String isSearchSecond = "";
    private int timeout = 60000;

    // 可配置参数
    private String startDate = "1995";
    private String endDate = "2013";
    private String paramStrs = "(专利—分类号:(C07))*$pub_org_code:CN*$patent_type:发明专利";
    private String classType = "patent-patent_element";
    private int pageSize = 2000;

    /**
     * 获得检索配置信息
     *
     * @return
     */
    public String getSearchConfig(){
        return String.format("【检索式　】%s\n【开始年　】%s\n【结束年　】%s\n【每页数目】%d",
                paramStrs, startDate, endDate, pageSize);
    }

    /**
     * 获得数目进度配置信息
     *
     * @return
     */
    public String getNumConfig(){
        return String.format("总数目: %d, 每页数目: %d, 进度: %d / %d", this.totalNum, this.pageSize, this.pageNum, this.totalPageNum);
    }

    /**
     * 转为map形式
     */
    public Map<String, String> toMap() {
        Map<String, String> datas = new HashMap<>();
        datas.put("paramStrs", paramStrs);
        datas.put("startDate", startDate);
        datas.put("endDate", endDate);
        datas.put("updateDate", updateDate);
        datas.put("classType", classType);
        datas.put("pageNum", pageNum + "");
        datas.put("pageSize", pageSize + "");
        datas.put("sortFiled", sortFiled);
        datas.put("isSearchSecond", isSearchSecond);
        return datas;
    }

    /**
     * 第一次获取map
     *
     * @return
     */
    public Map<String, String> toFirstMap() {
        Map<String, String> datas = toMap();
        datas.put("pageSize", "1");
        return datas;
    }

    /**
     * 下一页
     */
    public void nextPage() {
        this.pageNum++;
    }

    public int getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(int totalNum) {
        this.totalNum = totalNum;

        // 计算总页数
        this.totalPageNum = totalNum / pageSize;
        this.totalPageNum = totalNum % pageSize == 0 ? totalPageNum : totalPageNum + 1;
    }

    public int getTotalPageNum() {
        return totalPageNum;
    }

    public void setTotalPageNum(int totalPageNum) {
        this.totalPageNum = totalPageNum;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getStartDate() {
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    public String getParamStrs() {
        return paramStrs;
    }

    public void setParamStrs(String paramStrs) {
        this.paramStrs = paramStrs;
    }

    public String getClassType() {
        return classType;
    }

    public void setClassType(String classType) {
        this.classType = classType;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public String getSortFiled() {
        return sortFiled;
    }

    public void setSortFiled(String sortFiled) {
        this.sortFiled = sortFiled;
    }

    public String getIsSearchSecond() {
        return isSearchSecond;
    }

    public void setIsSearchSecond(String isSearchSecond) {
        this.isSearchSecond = isSearchSecond;
    }
}
